home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MATH.SWG / 0011_PERMUTA2.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  2KB  |  75 lines

  1. {
  2. I'm working on some statistical process control Charts and am
  3. learning/using Pascal. The current Chart Uses permutations and
  4. I have been successful in determing the number of combinations
  5. possible, but I want to be able to choose a few of those possible
  6. combinations at random For testing purposes.
  7.  
  8. Through some trial and error, I've written the following Program
  9. which calculates the number of possible combinations of x digits
  10. with a certain number of digits in each combination. For example
  11. a set of 12 numbers With 6 digits in each combination gives an
  12. answer of 924 possible combinations. After all that, here is the
  13. question: Is there a Formula which would calculate what those 924
  14. combinations are? (ie: 1,2,3,4,5,6 then 1,2,3,4,5,7 then 1,2,3,4,5,8
  15. ... 1,2,3,4,5,12 and so on? Any help would be appreciated and any
  16. criticism will be accepted.
  17. }
  18.  
  19. Program permutations;
  20.  
  21. Uses Crt;
  22.  
  23. Type hold_em_here = Array[1..15] of Integer;
  24.  
  25. Var  numbers,combs,bot2a : Integer;
  26.      ans,top,bot1,bot2b : Real;
  27.      hold_Array : hold_em_here;
  28.  
  29. Function permutate_this(number1 : Integer) : Real;
  30. Var i : Integer;
  31.     a : Real;
  32. begin
  33.  a := number1;
  34.  For i := (number1 - 1) doWNto 1 do a := a  * i;
  35.  permutate_this := a;
  36. end;
  37.  
  38. Procedure input_numbers(Var hold_Array : hold_em_here; counter : Integer);
  39. Var i,j : Integer;
  40. begin
  41.  For i := 1 to counter do begin
  42.   Write(' Input #',i:2,': ');
  43.   READLN(j);
  44.   hold_Array[i] := j;
  45.  end;
  46. end;
  47.  
  48. Procedure show_numbers(hold_Array : hold_em_here; counter : Integer);
  49. Var i,j : Integer;
  50. begin
  51.  WriteLN;
  52.  Write('Array looks like this: ');
  53.  For i := 1 to counter do Write(hold_Array[i]:3);
  54.  WriteLN
  55. end;
  56.  
  57. begin
  58.  ClrScr;
  59.  WriteLN;
  60.  WriteLN('  Permutations');
  61.  WriteLN;
  62.  Write('     Enter number of digits (1-15): ');
  63.  READLN(numbers);
  64.  Write('Enter number in combination (2-10): ');
  65.  READLN(combs);
  66.  top := permutate_this(numbers);
  67.  bot1 := permutate_this(combs);
  68.  bot2a := numbers - combs;
  69.  bot2b := permutate_this(bot2a);
  70.  ans := top/(bot1*bot2b);
  71.  WriteLN('   total permutations For above is: ',ans:3:0);
  72.  WriteLN;
  73.  input_numbers(hold_Array,numbers);
  74.  show_numbers(hold_Array,numbers);
  75. END.